<%@ page language="java" import="java.util.*,com.king.cms.common.*,com.king.cms.db.DBOperator" pageEncoding="UTF-8"%>
 
<%@ include file="/hotel/include/css.jsp"%><%-- /*包含css样式表*/ --%> 
<%
   String type = request.getParameter("type");
   String title = "会议地点";
   if(null != type){
      if("0".equals(type)){
         title = title;
      }
      if("1".equals(type)||"2".equals(type)){
         title = "播放地点";
      }
      
   } 
   String area = (String)request.getAttribute("area");
   List areaLcd = (List)request.getAttribute("dataList"); 
   String g = "";
    
   if(null != areaLcd && areaLcd.size()>0){
      for(int i = 0;i<areaLcd.size();i++){
          Map map = (Map)areaLcd.get(i);
          if(map.get("isSelect")!=null){
          	g = map.get("CLIENT_GROUP")+"";
          	break;
          }
      }
   }
   List group = (List)request.getAttribute("group");
   String firstGroup=""; 
   StringBuffer singleIdStr = new StringBuffer();
   StringBuffer mixIdStr = new StringBuffer();
   StringBuffer groupIdStr = new StringBuffer();
   String fileName = (String)request.getAttribute("back");
 %> 

<html>
<head>
<title>信息发布系统-<%=title%></title>
<meta  http-equiv="Expires"     CONTENT="0">           
<meta  http-equiv="Cache-Control"     CONTENT="no-cache">           
<meta  http-equiv="Pragma"     CONTENT="no-cache"> 
<script language="javaScript">
function changeview(id){ 
  var groups = document.getElementsByName('group');
  for(var i = 0;i<groups.length;i++){ 
  	   var vv = groups[i].value;
  	   var temp = 'lcd_'+vv;
  	   var objs = document.getElementsByName(temp);
  	   if(groups[i].checked) 
	  	   for(var j =0;j<objs.length;j++){
	  	       	 objs[j].disabled=false;
	  	   }
	  	 else
	  	 	for(var j =0;j<objs.length;j++){
	  	 	     if(objs[j].checked)
	  	 	        objs[j].checked=false;
	  	       	 objs[j].disabled=true;
	  	   }
  }    
}  
function changeview1(id){ 
  
  	   var temp = 'lcd_'+id;
  	   var objs = document.getElementsByName(temp); 
  	   for(var j =0;j<objs.length;j++){
  	       	 objs[j].disabled=true;
  	   }
	   
     
}  
function changeview2(){ 
     var objec = document.getElementsByName('group'); 
     for(var k = 0;k<objec.length;k++){ 
     
             if(k == 0)
             objec[k].checked=true;
     }
} 
function selectRoom(){
	var nameStr = '';
    var idStr = '';
    var contentStr = ''; 
    var lcdtype = '';
    var str = '';
    var group ='';
     var objec = document.getElementsByName('group');
     var flag = false;
     for(var k = 0;k<objec.length;k++){
          if(objec[k].checked){
             flag = true;
             group = objec[k].value;
             break;
           }
     }
     if(!flag){
       alert('请选择LCD显示屏组');
       return;
       }
    var lcdtype = document.getElementById('group_'+group).value;
    var lcd = document.getElementsByName('lcd_'+group);
    var lcdname = document.getElementsByName('name_'+group);
    if(lcd.length>0){
       for(var i =0;i<lcd.length;i++){
           if(lcd[i].checked){
              idStr+=lcd[i].value+',';
              nameStr+=lcdname[i].value+',';
              contentStr+='null#';
           }
       }
    } 
   if(''==idStr){
      alert("请选择客户端");
      return;
   }
   
   opener.form1.fieldflag.value=lcdtype; 
   opener.form1.hytzPortName.value=nameStr;
   opener.form1.hytzPort.value=idStr;
   opener.form1.content.value=contentStr;
   if('0' == <%=type%>){ 
	   if(opener.refresh){
	      opener.refresh();
	   }
   }
   window.close();
   
} 
 
     function   addContent(id){       
        var obj = document.getElementById('div_'+id); 
        obj.insertAdjacentHTML('BeforeEnd','<br><input   type="text" class="area100" onblur="return docheck(this)" name="lineCon_'+id+'"   size=22>');   
           
      }
       
/*取得字符串的字节长度*/
function strlen(str)
{ var i;
  var len;
 len=0;
for(i=0;i<str.length;i++)
{
if(str.charCodeAt(i)>255)
  len+=2;
  else
  len++;
}
return len;
}   

</script>
<head>
</head>
<body >
<form name="form1"   method="post" action=""> 
<center>
 <table border="0" align="center" cellpadding="4"    cellspacing="1" style="border-collapse: collapse;" bordercolor="#111111"   width="98%"   >
 
  <tr align="center">
    <td class="top_td" align="left" colspan=2> <b>终端LCD选择</b> </td>
  </tr>  
     
    <tr id="fivearea"   valign="top" height="600">
    <td class="td2"   width="600" height="600" align="center"><img src="<%=path %>/previewimage/<%=fileName %>" align="left"></td>
    <td >
    <table algin="left" valign="top"> 
       <%if(group != null && group.size() > 0){ 
            int count = 0;
            for(int j = 0;j<group.size();j++){
                 Map mm = (Map)group.get(j);
                 
                 String groupId = mm.get("ID")+"";  
                 groupIdStr.append(groupId).append("#");
                 DBOperator dbo = new DBOperator(session.getServletContext());
                 List list = dbo.select("select id from cms_client where client_group=? and client_desc=?",new Object[]{groupId,area});
                 if(list != null && list.size() == 0)
                    continue;
                 if("".equals(g)){
                      firstGroup += groupId+"#";
                      if(count == 0)
                         g = groupId;
                       
                 }
                 count++;
               %>
              <tr>
              <td><b><input type="hidden" name="group_<%=groupId%>" value="<%=mm.get("INPUT_SIZE") %>">
              <input type="radio" name="group" id="<%=groupId%>_id" onclick="changeview('<%=groupId%>')" value="<%=groupId%>" <%if(g.equals(groupId)){out.println("checked");} %>>&nbsp;<%=mm.get("GROUP_NAME") %></b> </td> 
             </tr>    
             <%
            
              for(int i = 0;i<areaLcd.size();i++){
                 Map m = (Map)areaLcd.get(i);
                 String id = m.get("ID")+"";
                 String clientgroup = m.get("CLIENT_GROUP")+"";
                 if(!groupId.equals(clientgroup))
                    continue;
              %>
               
		       <tr> 
		        <td nowrap>
		        <table align="left">
			        <tr>
			        <td width="100%" nowrap >
		        <input type="checkbox" value="<%=id%>" name="lcd_<%=groupId%>" <%if(!"".equals(g)&&!g.equals(groupId)){out.println(" disabled=true" );} %>   <%if(m.get("isSelect")!=null  ){out.print("checked");} %> ><b><%=m.get("CLIENT_NAME") %>
		            (<%=m.get("CLIENT_ADDRESS") %>)</b>  
		        	<input type="hidden" name="name_<%=groupId%>" value="<%=m.get("CLIENT_NAME") %>">
		        	</td>
		        	</tr>
		        	</table>
		        	</td> 
		      </tr>  
	      <%}%>
        <%} }%>
    </table>
    </td>
  </tr> 
  <tr>
    <td   colspan="2" align="right">
    	 <input type="hidden" name="singleStr" value="<%=singleIdStr%>">
    	 <input type="hidden" name="mixStr" value="<%=mixIdStr%>">
    	 <input type="hidden" name="groupStr" value="<%=groupIdStr%>">
    <input type="button" value="确定" class="area100" onclick="javaScript:selectRoom();">&nbsp;&nbsp;
    <input type="button" value="关闭" class="area100" onclick="javaScript:window.close();">
    </td>
  </tr>
 
</table> 
</center>
 
</form> 
</body>
</html>
<script>
	var firstStr ='<%=firstGroup%>';
 	if('null'!= firstStr){
 		var strt = firstStr.split('#');
 		if(strt!=null){
 		  for(var i = 1;i<strt.length;i++){  
 	   	       changeview1(strt[i]);
 	   	  }
 	   	  changeview2();
 	   }
 	   }
</script>
 